<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="../vue.js"></script>
    <title>Document</title>
    <style>
      *{
        padding: 0;
        margin: 0;
        list-style: none;
      }
      #app{
        width: 300px;
        height: 200px;
        margin: 0 auto;
      }

      input{
        width: 90px;
        height: 25px;
        margin-left: 60px;
        margin-top: 50px;
        border-radius: 20px;
        font-size: 14px;
        
      }

      ul{
        width: 150px;
        margin-left: 50px;
        margin-top: 10px;

      }

      li{
        width: 150px;
        height: 30px;
        font-weight: bold;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border: 1px solid black;
        border-radius: 30px;
        padding: 10px;
        margin-bottom: 10px;
      }

      button{
        width: 50px;
        height: 30px;
        background-color: yellowgreen;
        border-radius: 10px;
        color: white;
      }

      div:last-of-type{
        margin-left: 100px;
      
      }
    </style>
  </head>
  <body>

    <div id="app">
      <!-- 
        1.有待办事项展示待办事项，没有则显示空空如也
        2.输入内容后，下次输入前应该清除上次的
        3.删除功能
        4.加分项 样式写好看点
       -->
      <input type="text" v-model="myToDo" />
      <button @click="add">添加</button>
      <ul>
        <li v-for="(item,index) in list" :key="index">
          {{item}}
          <button @click="del(index)">删除</button>
        </li>
      </ul>
      <div v-show="!list[0]">空空如也～</div>
      <!-- v-show 数组为空时 是假 ，取反为真 就会显示 -->
    </div>


    <script>
      var app = new Vue({
        el: "#app",
        data: {
          myToDo: "",
          list: ["吃饭", "睡觉", "打豆豆"],

        },
        methods: {
          //添加待办事项
          add() {
            //输入为空不添加
            if(this.myToDo==''){
               alert('请输入内容');
               return;
            }
            this.list.push(this.myToDo);
            this.myToDo='';  //输入内容后输入框为空

          },
          //删除待办事项
          del(index) {
            this.list.splice(index,1);
          },
        },
      });
    </script>

  </body>
</html>
